package cn.com.shbs.Service.NCardService;

import cn.com.shbs.Dao.BaseNcard.BaseNcardDao;
import cn.com.shbs.Dao.BaseNcardSerive.BaseNcardSeriveDao;
import cn.com.shbs.model.BaseNcard;
import cn.com.shbs.model.BaseNcardSerive;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class NcardServiceImpl implements INcardService{
    static Logger logger = LoggerFactory.getLogger(NcardServiceImpl.class);
    @Autowired
    public BaseNcardDao baseNcardDao;
    @Autowired
    public BaseNcardSeriveDao baseNcardSeriveDao;

    @Override
    @Transactional(rollbackFor=Exception.class)
    public void insertNcard(BaseNcard baseNcard, List<BaseNcardSerive> ncardSeriveList) throws Exception {
        logger.info("UserInfoServiceImpl.insertNcard() 方法 start");

        try{
            //添加次卡基本信息
            baseNcardDao.insertBaseNcard(baseNcard);
            if(ncardSeriveList.size()>0){
                for(BaseNcardSerive card:ncardSeriveList){
                    //添加次卡基本服务信息
                    baseNcardSeriveDao.insertBaseNcardService(card);
                }
            }

        }catch (Exception e){
            logger.error("NcardServiceImpl.insertNcard()",e);
            throw  e;
        }

        logger.info("NcardServiceImpl.insertNcard() 方法 end");

    }
}
